package dht.tool;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;
import java.util.Vector;

import dht.entity.GlobalVariables;

public class FileGenerator {

	public static HashMap<String, Integer> generate(int number, int maxBlock)
			throws IOException {
		Scanner cin = new Scanner(new File(GlobalVariables.fakeFirstName));
		Vector<String> firstName = new Vector<String>();
		while (cin.hasNext()) {
			firstName.add(cin.next());
		}
		cin = new Scanner(new File(GlobalVariables.fakeLastName));
		Vector<String> lastName = new Vector<String>();
		while (cin.hasNext()) {
			lastName.add(cin.next());
		}
		cin.close();
		Random ran = new Random(GlobalVariables.seed);
		HashMap<String, Integer> fileName2BlockNum = new HashMap<String, Integer>();
		for (int i = 0; i < number; ++i) {
			String fileName = "";
			do {
				fileName = firstName.get(ran.nextInt(firstName.size()))
						+ lastName.get(ran.nextInt(lastName.size()));
			} while (fileName2BlockNum.containsKey(fileName));
			fileName2BlockNum.put(fileName, ran.nextInt(maxBlock));
		}
		return fileName2BlockNum;
	}

}
